package day13.CollectionTask;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class TaskFour {
    public static void main(String[] args) {
        List<Blog> list = new ArrayList<>();
        list.add(new Blog(1, "将进酒", "诗", "天生我材必有用", 100));
        list.add(new Blog(2,"我的词", "词",  "天生我材必有用", 999));
        list.add(new Blog(3, "诗2", "诗", "今天去玩", 666));
        list.add(new Blog(4, "摩罗根","词",  "天生我材必有用", 333));
        list.add(new Blog(5,"诗3", "诗",  "天生我材必有用", 7770));
        String str = "诗";
        //根据博客类别查询博客信息
        for (Blog blog : list) {
            if (blog.getCategory().equals(str))
                System.out.println(blog);
        }
        //根据标题查询博客信息
        String str2="将进酒";
        for (Blog blog : list) {
            if (blog.getTitle().equals(str))
                System.out.println(blog);
        }
        // 根据点赞数量获取排名前三的博客信息
        list.sort(new Comparator<Blog>() {
            @Override
            public int compare(Blog o1, Blog o2) {
                return o2.getNumber()-o1.getNumber();
            }
        });
        System.out.println(list);
//        Collections.sort(list, Comparator.comparingDouble(Blog::getNumber).reversed());
        System.out.println("点赞排名前三的博客信息为：");
        for(int a=0;a<3;a++){
            System.out.println(list.get(a));
        }
    }
}

class Blog {
    //博客id、标题、类别、内容、点赞数量
    private int id;
    private String title;
    private String category;
    private String content;
    private int number;

    public Blog() {
    }

    public Blog(int id, String title, String category, String content, int number) {
        this.id = id;
        this.title = title;
        this.category = category;
        this.content = content;
        this.number = number;
    }

    /**
     * 获取
     *
     * @return id
     */
    public int getId() {
        return id;
    }

    /**
     * 设置
     *
     * @param id
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * 获取
     *
     * @return title
     */
    public String getTitle() {
        return title;
    }

    /**
     * 设置
     *
     * @param title
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * 获取
     *
     * @return category
     */
    public String getCategory() {
        return category;
    }

    /**
     * 设置
     *
     * @param category
     */
    public void setCategory(String category) {
        this.category = category;
    }

    /**
     * 获取
     *
     * @return content
     */
    public String getContent() {
        return content;
    }

    /**
     * 设置
     *
     * @param content
     */
    public void setContent(String content) {
        this.content = content;
    }

    /**
     * 获取
     *
     * @return number
     */
    public int getNumber() {
        return number;
    }

    /**
     * 设置
     *
     * @param number
     */
    public void setNumber(int number) {
        this.number = number;
    }

    public String toString() {
        return "blog{id = " + id + ", title = " + title + ", category = " + category + ", content = " + content + ", number = " + number + "}";
    }
}
